<?php

namespace plugins\yongtai\model;


use plugins\yongtai\Utils;

class ArticleModel extends BaseModel
{
    protected $table = "yt_z_article";


    public function Detail($id)
    {
        $data = $this->find($id);
        if ($data) {
            $data = $data->toArray();
            $data['content'] = htmlspecialchars_decode($data['content'] ?: '');
            if ($data['more']) $data['more'] = unserialize($data['more']);
            $data = Utils::FormatThumb($data, cmf_get_plugin_config($this->plugin_name)['postfix_image_url']);
        }
        return $data;
    }

    public function SearchAllList($search_key = '')
    {
        $where = '';
        if ($search_key)
            $where = function ($query) use ($search_key) {
                $query->where('display', 1);
                $query->whereLike('title', "%$search_key%");
            };
        $res = $this->GetListAll($where);
        return Utils::ArrFormatThumb($res,  cmf_get_plugin_config($this->plugin_name)['postfix_image_url']);
    }
}
